package com.example.health_life.controller;

import com.example.health_life.Response;
import com.example.health_life.dao.Comment;
import com.example.health_life.dto.CommentDTO;
import com.example.health_life.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 获取评论列表
     * @param status 评论状态：1-正常，-1-删除，0-全部
     * @return 评论列表
     */
    @GetMapping("/comments")
    public Response <List<Comment>> getCommentList(@RequestParam(required = false, defaultValue = "1") Integer status) {
        return Response.newSuccess(commentService.getCommentList(status));
    }

    @GetMapping("/comments/{id}")
    public Response <Comment> getCommentById(@PathVariable Integer id) {
        return Response.newSuccess(commentService.getCommentById(id));
    }

    /**
     * 根据用户ID获取评论列表
     * @param userId 用户ID
     * @param status 评论状态：1-正常，-1-删除，0-全部
     * @return 评论列表
     */
    @GetMapping("/comments/user/{userId}")
    public Response <List<Comment>> getCommentByUserId(@PathVariable Integer userId, 
            @RequestParam(required = false, defaultValue = "1") Integer status) {
        return Response.newSuccess(commentService.getCommentByUserId(userId, status));
    }

    /**
     * 根据类型和类型ID获取评论列表
     * @param type 评论类型
     * @param typeId 类型ID
     * @param status 评论状态：1-正常，-1-删除，0-全部
     * @return 评论列表
     */
    @GetMapping("/comments/{type}/{typeId}")
    public Response <List<Comment>> getCommentByTypeId(@PathVariable Byte type, 
            @PathVariable Integer typeId,
            @RequestParam(required = false, defaultValue = "1") Integer status) {
        return Response.newSuccess(commentService.getCommentByTypeId(type, typeId, status));
    }

    @PostMapping("/comments")
    public Response<Integer> addComment(@RequestBody CommentDTO commentDTO) {
        return Response.newSuccess(commentService.addComment(commentDTO));
    }

    @DeleteMapping("/comments/{id}")
    public Response <Integer> deleteComment(@PathVariable Integer id) {
        return Response.newSuccess(commentService.deleteComment(id));
    }

}
